/*
 * Ext JS Extends Library 2.1
 * Copyright(c) 2006-2008, Synchrophy, LLC.
 * licensing@synchrophy.com
 * 
 * http://synchrophy.com/license
 */
 
Ext.util.GridUtils=function(){}

Ext.util.GridUtils.prototype={
	getSelectedRecord:function(gridId)
	{
		return Ext.getCmp(gridId).getSelections();
	},
	refresh:function(gridpanel, o)
	{
		if(!gridpanel)
			return false;
			
		var grid ;
		
		if(typeof gridpanel == "string")
		{
			grid = Ext.getCmp(gridpanel);
		}
		else
		{
			grid = gridpanel;
		}
		
		var param = new Object();
		
		if(grid.store.lastOptions)
			Ext.apply(param, grid.store.lastOptions);
		
		if(o)
			Ext.apply(param, o);
		
		grid.store.load(param);
		
		delete param;
		
		return grid;
	}
};

Ext.util.FormUtils=function(){}

Ext.util.FormUtils.prototype={
	clear:function(formpanel)
	{
		if(!formpanel)
			return false;
		var form;
		
		if(typeof formpanel == "string")
		{
			form = Ext.getCmp(formpanel);
		}
		else
		{
			form = gridpanel;
		}
		
		indexs = new Array();
		values = new Array();
		
		if(form.items.items)
		{
			idx = 0;
			
			for(ind = 0; ind < form.items.items.length;)
			{
				if(form.items.items[ind].readOnly)
				{
					indexs[idx] = ind;
					values[idx] = form.items.items[ind].value;
					idx++;
				}
				
				 ind ++;
			}
		}
		
		form.form.reset();
		
		for(ind = 0; ind < indexs.length;)
		{
			form.items.items[indexs[ind]].setValue(values[ind]);
			ind ++;
		}
		
		delete ind;
		delete indexs;
		delete values;
		
		return form;
	},
	reset:function(formpanel)
	{
		if(!formpanel)
			return false;
		var form;
		
		if(typeof formpanel == "string")
		{
			form = Ext.getCmp(formpanel);
		}
		else
		{
			form = gridpanel;
		}
		
		form.form.reset();
		
		if(form.reader&&form.reader.jsonData[form.reader.meta.root]&&form.reader.jsonData[form.reader.meta.root][0])
		{
			for(ind = 0 ; ind < form.form.items.items.length;)
			{
				field = form.items.items[ind];
				field.setValue(form.reader.jsonData[form.reader.meta.root][0][field.dataIndex]);
				ind ++;
			}
		}
		
		delete ind;
		delete field;
		return form;
	},
	getLoadData:function(form)
	{
		if(form.reader&&form.reader.jsonData[form.reader.meta.root]&&form.reader.jsonData[form.reader.meta.root][0])
		{
			return form.reader.jsonData[form.reader.meta.root][0];
		}
		else
			return null;
	},
	getLoadDataFieldValue:function(form, fname)
	{
		if(form.reader&&form.reader.jsonData[form.reader.meta.root]&&form.reader.jsonData[form.reader.meta.root][0])
		{
			return form.reader.jsonData[form.reader.meta.root][0][fname];
		}
		else
			return null;
	}
};

Ext.util.TreeUtils=function(){}

Ext.util.TreeUtils.prototype={	
	reloadnode:function(treepanel,nodeid)
	{
		var node;
		
		if(typeof treepanel == "string")
			node = Ext.getCmp("forumtreepanel").getNodeById(nodeid);
		else
			node = treepanel.getNodeById(nodeid);
		
		if(node)
		{
			if(node.isExpanded())			
				node.reload();
			else
				node.loaded = false;
		}
		
		delete node;
	}
};
 
Ext.grid.SeqNumberer = function(config){
    Ext.apply(this, config);
    if(this.rowspan){
        this.renderer = this.renderer.createDelegate(this);
    }    
};

Ext.grid.SeqNumberer.prototype = {
    /**
     * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
     * number column (defaults to '').
     */
    header: "",
    /**
     * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
     */
    width: 23,
    /**
     * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
     */
    sortable: false,

    // private
    fixed:true,
    menuDisabled:true,
    dataIndex: '',
    id: 'numberer',
    rowspan: undefined,

    // private
    renderer : function(v, p, record, rowIndex){
        if(this.rowspan){
            p.cellAttr = 'rowspan="'+this.rowspan+'"';
        }
        
        if(record.get("seq"))
        {
        	return record.get("seq");
        }
        else
        	return rowIndex+1;
    }
};